﻿/*
Copyright (C) 2010 INOUE Hiroyuki

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

using System;

namespace CodePlex.Dombly.DiskUsage.ConsoleApplication.Extensions
{
    /// <summary>
    /// Extends interface that provides file-size property by adding method 
    /// to write its information on Console.Out.
    /// </summary>
    static class WriteInfoExtensions
    {
        #region constants
        /// <summary>
        /// Format string for printing file size.
        /// </summary>
        const string SizeFormat = "###,###,###,##0";
        #endregion

        #region extend methods
        /// <summary>
        /// Write a one-line information of specified FileSystem object 
        /// on the console, which reports the file size of the object.
        /// </summary>
        /// <param name="i">FileSystem object to report.</param>
        internal static void WriteInfo(this BusinessLogic.IFileSystem i)
        {
            Console.WriteLine("{0}\t{1}",
                i.FileSize
                 .ToString(SizeFormat)
                 .PadLeft(SizeFormat.Length),
                i.FullName
                );
            Console.Out.Flush();
        }
        /// <summary>
        /// Write a one-line information of file size.
        /// </summary>
        /// <param name="i">File-size information to report.</param>
        internal static void WriteInfo(this IFileSizeInfo i)
        {
            Console.WriteLine("{0}\t{1}",
                i.FileSize
                 .ToString(SizeFormat)
                 .PadLeft(SizeFormat.Length),
                i.FullName
                );
            Console.Out.Flush();
        }
        #endregion
    }
}
